<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        // 1.求数组中所有元素的和
        var arr=[123,43,643,231,34]
        var sum=0;
        for(var i=0;i<arr.length;i++){
            sum+=arr[i];
        }
        console.log(sum);
        console.log("---------------");


        // 2.让数组中的元素交换位置
        var arr2=[321,12,533]
        var num=arr2[1];
        arr2[1]=arr2[2];
        arr2[2]=num;
        console.log(arr2);
        console.log("---------------");


        // 3.求数组的最大数和最小数
        var arr3=[346,52,46,22,5433,5]
        var max=arr3[0];
        var min=arr3[0];
        for(var t=1;t<arr3.length;t++){
            if(arr3[t]>max){
                max=arr3[t];
            }
            if(arr3[t]<min){
                min=arr3[t];
            }
        }
        console.log(min,max);
        console.log("---------------");


        // 4.求数组的最小数的下标
        var arr4=[34,435,21,15,35,2235]
        var min2=arr4[0];
        var minIndex=0;
        for(var r=1;r<arr4.length;r++){
            if(arr4[r]<min2){
                min2=arr4[r];
                minIndex=r;
            }
        }
        console.log(minIndex);
    </script>
</body>
</html>